﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Rappelz.GameServer
{
    public class PartyManager
    {
        public enum PartyType : int
        {
            Unknown = -1,
            Normal = 0,
            RaidAttackTeam = 1,
            SeigeAttackTeam = 2,
            Huntaholic = 3,
        }

        public enum ItemShareMode : int
        {
            Monopoly = 0,
            Random = 1,
            Linear = 2,
        }

        public class PartyMemberTag
        {
            public bool bIsOnline;// Data           :     this+0x0, Member, Type: bool, 
            public int sid;// Data           :     this+0x4, Member, Type: int, 
            public string strName;// Data           :     this+0x8, Member, Type: class std::basic_string<char,std::char_traits<char>,std::allocator<char> >, 
            public int nLevel;// Data           :     this+0x24, Member, Type: int, 
            public int nJobId;// Data           :     this+0x28, Member, Type: int, 
        }

        public class AttackTeamInfo
        {
            // Function       :     public void AttackTeamInfo(const struct PartyManager::AttackTeamInfo &)
            // Function       :     public void PartyManager::AttackTeamInfo::AttackTeamInfo()
            // Function       :     public void PartyManager::AttackTeamInfo::~AttackTeamInfo()
            public int nRaidPassword;// Data           :     this+0x0, Member, Type: int, 
            public int nLeadPartyId;// Data           :     this+0x4, Member, Type: int, 
            public int nGuildId;// Data           :     this+0x8, Member, Type: int, 
            public int nMaxGuildParty;// Data           :     this+0xC, Member, Type: int, 
            public List<PartyInfo> vPartyList = new List<PartyInfo>();
        }

        public class PartyInfo
        {
            public int nPartyPassword;// Data           :     this+0x0, Member, Type: int, 
            public int nPartyId;// Data           :     this+0x4, Member, Type: int, 
            public int nLeaderSID;// Data           :     this+0x8, Member, Type: int, 
            public ItemShareMode eShareMode;// Data           :     this+0xC, Member, Type: enum PartyManager::_ITEM_SHARE_MODE, 
            public PartyType ePartyType;// Data           :     this+0x10, Member, Type: enum PartyManager::_PARTY_TYPE, 
            public string strPartyName;// Data           :     this+0x14, Member, Type: class std::basic_string<char,std::char_traits<char>,std::allocator<char> >, 
            public string strLeaderName;// Data           :     this+0x30, Member, Type: class std::basic_string<char,std::char_traits<char>,std::allocator<char> >, 

            public int nLeaderJobId;// Data           :     this+0x4C, Member, Type: int, 
            public List<PartyMemberTag> vMemberNameList = new List<PartyMemberTag>();// Data           :     this+0x50, Member, Type: class std::vector<PartyManager::PartyMemberTag,std::allocator<PartyManager::PartyMemberTag> >, 
            public List<uint> vOnlineList = new List<uint>();// Data           :     this+0x60, Member, Type: class std::vector<unsigned int,std::allocator<unsigned int> >, 

            public int nLastItemAcquirerIdx;// Data           :     this+0x70, Member, Type: int, 
            public AttackTeamInfo pAttackTeamInfo;// Data           :     this+0x74, Member, Type: struct PartyManager::AttackTeamInfo *, 
        }

        /// <summary>
        /// The instance!
        /// </summary>
        protected static PartyManager m_instance;

        /// <summary>
        /// Returns the instance
        /// </summary>
        public static PartyManager Instance
        {
            get
            {
                if (m_instance == null)
                    m_instance = new PartyManager();
                return m_instance;
            }
        }

// 
// UserDefinedType: PartyManager
// VTable         :   , Type:  *
// Enum           :   <unnamed-tag>, Type: int
// Data           :     constant 0x8, Constant, Type: int, MAX_PARTY_MEMBER
// Enum           :   <unnamed-tag>, Type: int
// Data           :     constant 0x0, Constant, Type: int, NORMAL_PARTY
// Data           :     constant 0x1, Constant, Type: int, RAID_PARTY
// Data           :     constant 0x2, Constant, Type: int, SIEGE_GUILD_PARTY
// Data           :     constant 0x3, Constant, Type: int, SIEGE_MERCENARY_PARTY
// UserDefinedType:   PartyFunctor
// VTable         :     , Type:  *
// Function       :     public bool operator()(unsigned int)
// Function       :     public void PartyFunctor(const struct PartyManager::PartyFunctor &)
// Function       :     public void PartyFunctor()
// Function       :     public struct PartyManager::PartyFunctor & operator=(const struct PartyManager::PartyFunctor &)
// UserDefinedType:   PartyMemberTagFunctor
// VTable         :     , Type:  *
// Function       :     public bool operator()(struct PartyManager::PartyMemberTag *)
// Function       :     public void PartyMemberTagFunctor(const struct PartyManager::PartyMemberTagFunctor &)
// Function       :     public void PartyMemberTagFunctor()
// Function       :     public struct PartyManager::PartyMemberTagFunctor & operator=(const struct PartyManager::PartyMemberTagFunctor &)
// Function       :   public static class PartyManager & PartyManager::GetInstance()
// Function       :   public bool PartyManager::Init()
// Function       :   public bool PartyManager::DeInit()
// Function       :   public bool PartyManager::CanJoinGuildParty(int)
// Function       :   public bool CanJoinMercenaryParty(int)
// Function       :   public bool PartyManager::IsExistAttackTeam(int)
// Function       :   public int PartyManager::GetAttackTeamLeadPartyIDByGuildID(int)

        public int GetAttackTeamLeadPartyID(int nPartyId)
        {
            return 0;
        }
// Function       :   public bool PartyManager::MakeAttackTeam(const char *, int, int, bool)
// Function       :   public bool PartyManager::JoinAttackTeam(int, const char *)
        public int GetAttackTeamGuildID(int nPartyID)
        {
            return 0;
        }

        public bool IsAttackTeamParty(int nPartyID)
        {
            return false;
        }

        public PartyType GetPartyType(int nPartyID)
        {
            return PartyType.Normal;
        }
// Function       :   public int PartyManager::GetPartyPassword(const char *)
// Function       :   public int PartyManager::GetAttackTeamPassword(const char *)
// Function       :   public bool PartyManager::IsSomeoneInDungeon(int)
// Function       :   public bool PartyManager::MakeParty(const char *, int, const enum PartyManager::_PARTY_TYPE &)

        public bool DestroyParty(int nPartyId)
        {
            return false;
        }
// Function       :   public bool PartyManager::DestroyParty(const char *)

        public int GetMemberCount(int nPartyID)
        {
            return 1;
        }
// Function       :   public int GetPartyID(const char *)
        public string GetPartyName(int nPartyID)
        {
            return "";
        }

//        public bool IsLeader(const char *, const char *)
    
        public bool IsLeader(int nPartyId, string szPlayerName)
        {
            return false;
        }
// Function       :   public bool PartyManager::IsMember(int, const char *)
// Function       :   public bool PartyManager::Promote(int, struct StructPlayer *)
// Function       :   public bool AutoPromote(int, const bool)
// Function       :   public void PartyManager::OnChangeCharacterName(int, const char *, const char *)

        public void OnChangeCharacterLevel(int nPartyID, string szName, int nLevel)
        {

        }

        public void OnChangeCharacterJob(int nPartyID, string szName, int nJobId)
        {

        }
// Function       :   public int PartyManager::GetMaxLevel(int)
// Function       :   public int PartyManager::GetMinLevel(int)
// Function       :   public int GetTotalLevel(int)
        public string GetLeaderName(int nPartyID)
        {
            return "";
        }
// Function       :   public bool PartyManager::JoinParty(const char *, struct StructPlayer *)
// Function       :   public bool PartyManager::JoinParty(int, struct StructPlayer *)
// Function       :   public bool PartyManager::LeaveParty(const char *, const char *)

        public bool LeaveParty(int nPartyId, string szName)
        {
            return false;
        }

// Function       :   public bool onLogin(const char *, struct StructPlayer *)

        public bool onLogin(int nPartyID, Player player)
        {
            return false;
        }
// Function       :   public bool onLogout(const char *, struct StructPlayer *)

        public bool onLogout(int nPartyID, Player player)
        {
            return false;
        }
// Function       :   public const enum PartyManager::_ITEM_SHARE_MODE PartyManager::GetShareMode(int)
// Function       :   public void PartyManager::SetShareMode(int, const enum PartyManager::_ITEM_SHARE_MODE &)
// Function       :   public struct StructPlayer * PartyManager::GetNextItemAcquirer(struct StructPlayer *, const class std::vector<StructPlayer *,std::allocator<StructPlayer *> > &)
// Function       :   public class std::basic_string<char,std::char_traits<char>,std::allocator<char> > PartyManager::GetRaidPartyInfo(int)
// Function       :   public unsigned int PartyManager::DoEachAttackTeamMember(int, struct PartyManager::PartyFunctor &)
// Function       :   public unsigned int PartyManager::DoEachAttackTeamMemberByGuildId(int, struct PartyManager::PartyFunctor &)

        public uint DoEachMember(int nPartyID, PartyFunctor fn)
        {
            uint result = 0;
            
            lock(this.m_IntfLock)
            {
                PartyInfo info = this.getPartyInfo(nPartyID);
                if (info != null)
                    result = this.doEachMember(info, fn);
            }
            return result;
        }

// Function       :   public unsigned int DoEachMember(const char *, struct PartyManager::PartyFunctor &)
// Function       :   public unsigned int DoEachMemberTag(const char *, struct PartyManager::PartyMemberTagFunctor &)
// Function       :   public unsigned int PartyManager::DoEachMemberTag(int, struct PartyManager::PartyMemberTagFunctor &)

        public void GetNearMember(Player pPtr, float distance, List<Player> vList)
        {

        }

// Function       :   public void GetOfflineMember(int, class std::vector<PartyManager::PartyMemberTag,std::allocator<PartyManager::PartyMemberTag> > &)
// Function       :   public void PartyManager::Push(struct GameDBManager::DBProc *)
// Function       :   public void PartyManager::onEndQuery()
// Function       :   public void PartyManager(const class PartyManager &)
// Function       :   public void PartyManager::PartyManager()
// Function       :   public void PartyManager::~PartyManager()
// Function       :   protected void PartyManager::loadPartyMemberTagList()
// Function       :   protected int PartyManager::_getPartyMemberTagList(const int, const int, class std::vector<PartyManager::PartyMemberTag,std::allocator<PartyManager::PartyMemberTag> > &)
// Function       :   protected void PartyManager::loadPartyList()
// Function       :   protected void PartyManager::finishLoading()
// Function       :   protected bool PartyManager::leaveParty(struct PartyManager::PartyInfo *, const char *)
// Function       :   protected bool PartyManager::joinParty(struct PartyManager::PartyInfo *, struct StructPlayer *)

        // Function       :   protected bool PartyManager::destroyParty(struct PartyManager::PartyInfo *)
// Function       :   protected struct PartyManager::AttackTeamInfo * PartyManager::makeAttackTeam(struct PartyManager::PartyInfo *, int, int)
// Function       :   protected bool PartyManager::joinAttackTeam(struct PartyManager::PartyInfo *, int)
// Function       :   protected struct PartyManager::PartyInfo * PartyManager::makeParty(int, const char *, int, const enum PartyManager::_ITEM_SHARE_MODE &, const enum PartyManager::_PARTY_TYPE &)
// Function       :   protected int PartyManager::allocPartyId()

        protected PartyInfo getPartyInfo(int nPartyID)
        {
            if(this.m_hshPartyID.ContainsKey(nPartyID))
                return this.m_hshPartyID[nPartyID];
            return null;
        }
// Function       :   protected struct PartyManager::PartyInfo * PartyManager::getPartyInfo(const char *)

        protected uint doEachMember(PartyInfo pInfo, PartyFunctor fn)
        {
            uint count = 0;

            foreach (uint handle in pInfo.vOnlineList)
            {
                fn.run(handle);
                count++;
            }
            return count;
        }

// Function       :   protected unsigned int PartyManager::doEachMemberTag(struct PartyManager::PartyInfo *, struct PartyManager::PartyMemberTagFunctor &)
// Function       :   protected bool PartyManager::signAsOnLine(struct PartyManager::PartyInfo *, struct StructPlayer *)
// Function       :   protected bool PartyManager::signAsOffLine(struct PartyManager::PartyInfo *, struct StructPlayer *)
        public int m_nMaxPartyId;                                                                                   // 0x4
        public object m_QueryLock = new object();                                                                   // 0x8
        public object m_IntfLock = new object();                                                                    // 0x48
        public Dictionary<string, PartyInfo> m_hshPartyName = new Dictionary<string, PartyInfo>();                  // 0x88
        public Dictionary<int, PartyInfo> m_hshPartyID = new Dictionary<int, PartyInfo>();                          // 0xA4
        public Dictionary<int, PartyMemberTag> m_hshPartyMemberTagList = new Dictionary<int, PartyMemberTag>();     // 0xC0
        public Dictionary<int, AttackTeamInfo> m_hshAttackTeamID = new Dictionary<int, AttackTeamInfo>();           // 0xDC
// Data           :   this+0xF8, Member, Type: class std::list<GameDBManager::DBProc *,std::allocator<GameDBManager::DBProc *> >, m_lQueryList
// UserDefinedType:     std::list<GameDBManager::DBProc *,std::allocator<GameDBManager::DBProc *> >
// 
// Data           :   this+0x104, Member, Type: struct DBConnection, m_DBConn
// UserDefinedType:     DBConnection
// 

    }
}
